//
//  SelectedFaFangZiYuanAlertView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/25.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "SelectedFaFangZiYuanAlertView.h"

@implementation SelectedFaFangZiYuanAlertView
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
        self.tableList.tableFooterView = [UIView new];
    }
    return self;
}
- (void)initSubView{
    [self addSubview:self.maskView];
    [_maskView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissView)];
    [_maskView addGestureRecognizer:tap];
    [self addSubview:self.tableList];
    [_tableList mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.width.equalTo(@502);
        make.height.equalTo(@300);
        make.centerY.equalTo(self.mas_centerY);
    }];
     
}

- (void)requestDataArr:(NSMutableArray *)dataListArr {
    self.datalistaArr = dataListArr;
    [self.tableList reloadData];
}


- (void)dismissView{
    [_maskView removeFromSuperview];
    [self removeFromSuperview];
}
- (UIView *)maskView{
    if (!_maskView) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = MASCKCOLOR;
        view.alpha = 0.4;
        _maskView = view;
    }
    return _maskView;
}
- (UITableView *)tableList{
    if (!_tableList) {
        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, APP_HEIGHT-84) style:UITableViewStylePlain];
        tableView.delegate  =self;
        tableView.dataSource = self;
        tableView.bounces = NO;
        [tableView registerClass:[SelectedFaFangZiYuanAlertCell class] forCellReuseIdentifier:@"SelectedFaFangZiYuanAlertCell"];
        tableView.backgroundColor = [UIColor whiteColor];
        _tableList = tableView;
    }
    return _tableList;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    SYDataResourceModel *fileModel = self.datalistaArr[section];
    return self.datalistaArr.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SelectedFaFangZiYuanAlertCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SelectedFaFangZiYuanAlertCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[SelectedFaFangZiYuanAlertCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SelectedFaFangZiYuanAlertCell"];
    }
    
    
    SYDataResourceFileModel *resourceModel = self.datalistaArr[indexPath.row];
    cell.titleLabel.text = resourceModel.name;
    cell.detailLabel.text = resourceModel.size;
//    cell.dateLabel.text = fileModel.sendDate;
    [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:resourceModel.icon] placeholderImage:[UIImage imageNamed:@"zy_collection_xjwjj"]];
    
    
    return cell;
}
#pragma mark - 添加资源选择视图
- (void)addResourcesViewController{
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (!_header) {
        _header = [[SelectedFaFangZiYuanAlertViewHeader alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 44)];
        _header.backgroundColor = CONTENTBACKCOLOR;
    }
    SYDataResourceModel *fileModel = self.datalistaArr[section];
    [_header.leftImageView sd_setImageWithURL:[NSURL URLWithString:fileModel.sourceIcon] placeholderImage:[UIImage imageNamed:@"zy_collection_xjwjj"]];
    _header.nameLabel.text = fileModel.courseName;
    _header.detailLabel.text = [NSString stringWithFormat:@"文件:%@  大小:%@",fileModel.files,fileModel.size];
    return _header;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *mainView = [[UIView alloc]init];
    return mainView;
}
@end
